﻿using BasicInformation.ApiRead.Application.Command.Location;
using BasicInformation.Domain;
using BasicInformation.ErrorCode;
using BasicInformation.Infrastructure.Implement;
using BasicInformation.Infrastructure.Interface;
using MediatR;
using Dapper;
using System.Text;

namespace BasicInformation.ApiRead.Application.Handler.Location
{
    public class GetLocationTypeHandler : IRequestHandler<GetLocationTypeCommand, ApiPaging<LocationTypeModel>>
    {
        private readonly DatabaseContext db;
        private readonly ILogger<GetLocationTypeHandler> logger;

        public GetLocationTypeHandler(DatabaseContext db,ILogger<GetLocationTypeHandler> logger)
        {
            this.db = db;
            this.logger = logger;
        }
        public async Task<ApiPaging<LocationTypeModel>> Handle(GetLocationTypeCommand request, CancellationToken cancellationToken)
        {
            ApiPaging<LocationTypeModel> result =new ApiPaging<LocationTypeModel>();
            var sql = @"SELECT * FROM locationtypemodel WHERE 1=1 ";
            var re= db.SqlSugar.Queryable<LocationTypeModel>();
            result.Data = re.ToList();
            result.Code = ApiEnum.OK;
            result.Msg = "库位类型查询成功";
            logger.LogInformation(result.Msg);
            return await Task.FromResult(result);
        }
    }   
}

